package edu.ynmd.cms.action;

import edu.ynmd.cms.model.News;
import edu.ynmd.cms.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;

@Controller
@CrossOrigin
@RequestMapping("manage")
public class AdminAction {

    @Autowired
    private ManageService manageService;



    @PostMapping("addNews")
    @ResponseBody
    public boolean addNews(@RequestBody News news) throws Exception{
        news.setPbdate(new Timestamp(System.currentTimeMillis()));
        return manageService.addNews(news);

    }


    @PostMapping("deleteNews")
    @ResponseBody
    public boolean deleteNews(@RequestBody News news) throws Exception{
        return manageService.deletenews(news.getNewsid());
    }

    @PostMapping("updateNews")
    @ResponseBody
    public boolean updateNews(@RequestBody News news) throws Exception{
        return manageService.updateNews(news);
    }


    @PostMapping("getSingleNews")
    @ResponseBody
    public News getSingleNews(@RequestBody News news) throws Exception{

        return manageService.getNews(news.getNewsid());
    }

    @GetMapping("getNewsList")
    @ResponseBody
    public List<News> getNewsList() throws Exception{

        return manageService.getNewsList();
    }




}
